package cn.xlmdz.subsoilerinfoquery.utils;

import android.content.Context;
import android.widget.Toast;

import cn.xlmdz.subsoilerinfoquery.app.MyApplication;

public class ToastUtil {
    private static Toast toast = null;

    /**
     * 直接输入
     *
     * @param context 上下文
     * @param msg     显示内容
     */
    public static void showTextToast(Context context, String msg) {
        if (toast == null) {
            toast = Toast.makeText(context, msg, Toast.LENGTH_SHORT);
        } else {
            toast.setText(msg);
        }
        toast.show();
    }

    /**
     * 直接输入
     *
     * @param msg 显示内容
     */
    public static void showTextToast(String msg) {
        if (toast == null) {
            toast = Toast.makeText(MyApplication.getAppContext(), msg, Toast.LENGTH_SHORT);
        } else {
            toast.setText(msg);
        }
        toast.show();
    }

    /**
     * 应用资源类型
     *
     * @param context 上下文
     * @param msg     资源id
     */
    public static void showTextToastById(Context context, int msg) {
        if (toast == null) {
            toast = Toast.makeText(context,
                context.getResources().getString(msg),
                Toast.LENGTH_SHORT);
        } else {
            toast.setText(msg);
        }
        toast.show();
    }

    /**
     * 应用资源类型
     *
     * @param msg 资源id
     */
    public static void showTextToastById(int msg) {
        if (toast == null) {
            toast = Toast.makeText(MyApplication.getAppContext(),
                MyApplication.getAppContext().getResources().getString(msg),
                Toast.LENGTH_SHORT);
        } else {
            toast.setText(msg);
        }
        toast.show();
    }
}